/**
 * 通过画图列子，实现桥接
 */



//画图函数
function drawRedCircle(r,x,y){
    console.log(`drawing red circle r = ${r} x = ${x} y=${y}`)
}

function drawBlueSquare(r,x,y){
    console.log(`drawing blue square r = ${r} x = ${x} y=${y}`)
}

class Shape{
    constructor(drawAPI){
        if(new.target==Shape){
            throw Error('cannot declare Shape object by new Shape')
        }
        this.drawAPI = drawAPI
    }
    draw(){}
}

class Circle extends Shape{
    constructor(r,x,y,api){
        super(api)
        this.x = x
        this.y = y
        this.r = r
    }
    //通过draw函数将画图函数和图形类之间桥接
    draw(){
        this.drawAPI(this.r,this.x,this.y)
    }
}

class Square extends Shape{
    constructor(l,x,y,api){
        super(api)
        this.x = x
        this.y = y
        this.l = l
    }
    //通过draw函数将画图函数和图形类之间桥接
    draw(){
        this.drawAPI(this.l,this.x,this.y)
    }
}

const circle = new Circle(43,2,3,drawRedCircle)
circle.draw()
const square = new Circle(43,2,3,drawBlueSquare)
square.draw()